#include "StdAfx.h"
#include "TinyDBManager.h"

CTinyDBManager::CTinyDBManager(void)
: m_DBInterface(NULL),
  m_dbtype(-1)
{
}

CTinyDBManager::~CTinyDBManager(void)
{
}

bool CTinyDBManager::openMysqlDBConnection(std::string connStr)
{
	if(m_DBInterface ==NULL)
	return false;

	return m_DBInterface->openConnection(connStr);
}

/*bool CTinyDBManager::loadDataFromDB()
{
	bool nRet =false;
	switch(m_dbtype)
	{
	case MYSQLDB:
		nRet = openMysqlDBConnection(m_connStr);
		break;
	default:
		return false;
		break;
	}

	if(nRet == false)
		return nRet;

	//for each mapper to load
	std::map<int,CTinyDBMapper*>::iterator it = m_Mappers.begin();
	for(;it != m_Mappers.end();++it)
	{
		it->second->loadData(m_dbtype,m_DBInterface);
	}

	return nRet;
}*/

/*void CTinyDBManager::pushMapper(int key, CTinyDBMapper* mapper)
{
	m_Mappers.insert(std::pair<int,CTinyDBMapper*>(key,mapper));
}*/

void CTinyDBManager::init(int dbtype, std::string & connstr)
{
	m_connStr = connstr;
	m_dbtype = dbtype;
	if(dbtype ==DBTYPE_MYSQL)
	{
		CTinyDBMysqlInterface * tempIF = new CTinyDBMysqlInterface();
		setDBInterface(tempIF);
		openMysqlDBConnection(m_connStr);
	}
}

/*CTinyDBMapper* CTinyDBManager::findMapper(int key)
{
	if(key<0)
		return NULL;
	std::map<int,CTinyDBMapper*>::iterator it = m_Mappers.find(key);

	if(it == m_Mappers.end())
		return NULL;

	return it->second;
}*/
